package com.baizhi.app.controller;

import com.baizhi.app.common.R;
import com.baizhi.dao.CmfzArticleDao;
import com.baizhi.dao.CmfzGuruDao;
import com.baizhi.dao.CmfzUserDao;
import com.baizhi.entity.CmfzArticle;
import com.baizhi.entity.CmfzGuru;
import com.baizhi.entity.CmfzUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("app/article")
public class AppArticleController {
    @Autowired
    private CmfzArticleDao cad;

    @Autowired
    private CmfzUserDao cud;
    @GetMapping("userToSomeGuru/{userId}")
    public R userToSomeGuru(@PathVariable("userId")int userId){
        CmfzUser cmfzUser = cud.selectById(userId);
        Integer guruId = cmfzUser.getGuruId();

        QueryWrapper<CmfzArticle> wrapper = new QueryWrapper<>();
        System.out.println(guruId);
        wrapper.eq("guru_id",guruId);
        List<CmfzArticle> cmfzArticles = cad.selectList(wrapper);
       // CmfzArticle cmfzArticle = cad.selectById(wrapper);
      //  CmfzArticle cmfzArticle = cad.selectOne(wrapper);
        return R.ok().put("data",cmfzArticles);

    }

}
